﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using DSS_XNA.Engine.Error;

namespace DSS_XNA.Engine.Timer
{
    public class FPSTimer
    {
        #region Properties

        public int LastSecond
        {
            get { return _lastSecond; }
        }
        private int _lastSecond = 0;

        public int FrameCounter
        {
            get { return _frameCounter; }
        }
        private int _frameCounter = 0;

        public int CurrentFPS
        {
            get { return _currentFPS; }
        }
        private int _currentFPS = 0;

        #endregion

        #region Public Methods

        public FPSTimer()
        {
        }

        public void Update(GameTime gameTime)
        {
            if (gameTime == null)
                throw new DSSException("'gameTime' is null.");

            if (this._lastSecond != gameTime.TotalRealTime.Seconds)
            {
                this._lastSecond = gameTime.TotalRealTime.Seconds;
                this._currentFPS = this._frameCounter;
                this._frameCounter = 0;
            }

            this._frameCounter++;
        }

        #endregion
    }
}
